﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Jzy.Core.Attach;

using Jzy.Core.Utility;
using Jzy.Model.SiteAdmin;
using Jzy.BLL.SiteAdmin;
using Jzy.Common;

namespace Jzy.Web.SiteAdmin.Picture
{
    public partial class GroupPictureBatchAdd : PageEdit
    {
        private string ArticleID
        {
            get
            {
                return Request["ArticleID"];
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            this.Form.Enctype = "multipart/form-data";
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            
            ImageBO picture = new ImageBO(TableName.CmsArticlePicture);


            ArticleBO article = new ArticleBO();
            MenuInfo menuInfo = article.GetInfo(ArticleID).MenuInfo;

           //不能用foreach，原因不明
            for (int i = 0; i < Request.Files.Count;i++ )
            {
                HttpPostedFile file = Request.Files[i];
                //判断图片格式
                string extention = System.IO.Path.GetExtension(file.FileName).ToLower();
                if (extention == ".jpg" || extention == ".png" || extention == ".gif" || extention == ".bmp")
                {
                    System.Drawing.Bitmap img = new System.Drawing.Bitmap(file.InputStream);
                    ImageInfo pictureInfo = new ImageInfo();
                    pictureInfo.Name = System.IO.Path.GetFileName(file.FileName);
                    pictureInfo.BindID = int.Parse(ArticleID);
                    pictureInfo.InputTime = DateTime.Now;
                    pictureInfo.Width = img.Width;
                    pictureInfo.Height = img.Height;
                    pictureInfo.Size = (int)file.InputStream.Length;
                    pictureInfo.Orders = picture.GetMaxOrder(pictureInfo.BindID);
                    article.SaveImage(pictureInfo, file, menuInfo);  
                 
                    
                    picture.Save(pictureInfo);


                }

            }

            JSUtil.RefreshView();
        }
    }
}
